<?php

// Where is the "tidy" command?

define('TIDY', '/usr/bin/tidy');

// Read the NOTEX service configuration file

include_once('../../../notex.php');
$notex = new NOTEX();

// Describe how to use this script

$params = array(
    'url' => 'The URL to translate into XHTML'
);
$notex->usage('xhtml.php will return the page at the URL as XHTML for your processing.', $params);

// Cache the URL

$url = param('url');
if (!$url) $notex->error('No URL');
$html = GET($url);

// Output the file as XHTML

$file = "../../cache/" . md5($url);
file_put_contents($file, $html);
passthru(TIDY . " -asxml $file");
unlink($file);

// END
